package com.soft.javase.day10.practice;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/5/4
 */
public class Filter {
    public static void main(String[] args) {
        String[] array = { "张三,男", "李四,女", "王二麻子,女" };

        List<String> list = new ArrayList<>();

        Predicate<String> isFemale = str -> {
            String gender = str.split(",")[1];
            return "女".equals(gender);
        };

        Predicate<String> isValidName = str -> {
            String name = str.split(",")[0];
            return name.length() == 4;
        };

        Predicate<String> and = isFemale.and(isValidName);

        for (String info : array)
            if (and.test(info)) {
                list.add(info);
            }

        list.forEach(System.out::println);
    }
}
